/**
 * 
 */
package com.sf.osms.dep.quartz;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.sf.novatar.cluster.IKeepAliveAndLockResolver;
import com.sf.osms.dep.processor.util.SwitchUtils;

/**
 * @author sfhq1469
 * DEP路由节点定时任务
 */
public class DepRouteUploadJob {
	
	private static Logger logger = LoggerFactory.getLogger(DepRouteUploadJob.class);
	
	public static final String LOCK_NAME = "depRoute_lock";
	
	@Autowired
	private  IKeepAliveAndLockResolver clusterSync;
	
	private @Autowired @Qualifier("depRouteUploadJobDetail") DepRouteUploadJobDetail depRouteUploadJobDetail;
	
	/***
     * 路由节点定时任务
     */
	public void job()
	{ 
		if(clusterSync.isLockedFor(LOCK_NAME)){
			return;
		}
		boolean lock = clusterSync.getLockFor(LOCK_NAME);
		if(!lock){
			return;
		} 
		logger.info("------------>DepRouteUploadJob start");

		try {
			if(SwitchUtils.getSwithBySystemName(SwitchUtils.FVP_SWITCH_NAME)){
				depRouteUploadJobDetail.depRouteUpload();
			}
		} catch (Exception e) {
			logger.error("------------>DepRouteUploadJob run error!"+e.getMessage()); 
			logger.error(e.getMessage(), e);
		} 	
		clusterSync.releaseLockFor(LOCK_NAME);  
		
		logger.info("------------>DepRouteUploadJob End");
	}  
	
}
